$(function() {
	calendar();
	closeRegistDiv();
	$('#cansel').bind('click', closeRegistDiv);
	$('input[type=text]').addClass('textBorder');
	$('#dialog').css('display', 'none');
	$('#title').addClass('titleDiv');
	$('#regist').bind('click', regist);
	showphoto();
});
// 将登录框显示
function showLoginDiv() {
	$('#dialog').dialog({
		title : "用户登录",
		modal : true,
		width : '300px',
		height : '150px',
		// bgiframe : true,
		// autoOpen : false,
		buttons : {
			登录 : function() {
				login();
			},
			取消 : function() {
				alert('你确定要取消嘛？');
				$(this).dialog("close");
			}
		}
	});
}
// 为text添加一个日历
function calendar() {
	$('#date').datepicker(
			{
				dateFormat : "yy-mm-dd",
				dayNames : [ "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" ],
				dayNamesMin : [ "日", "一", "二", "三", "四", "五", "六" ],
				monthNamesMin : [ "一", "二", "三", "四", "五", "六", "七", "八", "九",
						"十", "十一", "十二" ],
				monthNames : [ "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月",
						"九月", "十月", "十一月", "十二月" ],
				showMonthAfterYear : false,
				changeYear : true,
				changeMonth : true,
				buttonImage : '/Hippy_Zone/img/0.jpg',
				buttonText : 'Choose',
				defaultDate : +0,
				nextText : 'Later',
				showButtonPanel : true,
				showOptions : {
					direction : 'up'
				}
			});

}
// 隐藏注册div
function closeRegistDiv() {
	$('#registDiv').css('display', 'none');
}
// 显示注册div
function showRegistDiv() {
	$('#registDiv').css('display', 'block');
}
// ajax登录的方法
function login() {
	var name = $('#name').val();
	var pass = $('#pass').val();
	$.ajax({
		url : '/Hippy_Zone/loginServlet.do',
		type : 'post',
		data : {
			name : name,
			pass : pass
		},
		successs : function(data) {
			$('#name')[0].value = "";
			$('#pass')[0].value = "";
			$('#name')[0].focus();
			alert("1");
			alert(data);
		},
		error : function(xhr, msg) {
			alert(xnr.text);
			alert(msg);
		}
	});
}
function regist() {
	var nickname = $('#nickname').val();
	var age = $('#age').val();
	var pass = $('#pass').val();
	var repass = $('#repass').val();
	var sex = $('#sex').val();
	var birthday = $('#date').val();
	var address = $('#address').val();
	$.ajax({
		url : 'Hippy_Zone/registServlet.do',
		type : 'post',
		data : {
			nickname : nickname,
			age : age,
			pass : pass,
			sex : sex,
			birthday : birthday,
			address : address
		},
		success : function(data) {
			alert(nickname + "注册成功！");
		},
		error : function(a, b, c) {
			alert("errorMessage:" + c);
		},
		beforeSend : function() {
			if (nickname == "")
				alert('Nickname不能为空');
			if (age == "")
				alert('age不能为空');
			if (pass == "")
				alert('pass不能为空');
			if (repass == "")
				alert('repass不能为空');
			if (pass == repass)
				alert('两次密码不相同');
			if (sex == "")
				alert('性别不能为空');
			if (birthday == "")
				alert('生日不能为空');
			if (address == "")
				alert('地址不能为空');
			$('#registDiv').html('zhuce.......');
		}
	});
}
function showphoto() {
	var viewer = new PhotoViewer();
	viewer.add('/Hippy_Zone/img/0.jpg');
	viewer.add('/Hippy_Zone/img/bg.jpg');
	viewer.add('/Hippy_Zone/img/bg1.jpg');
	viewer.add('/Hippy_Zone/img/logo.png');
	viewer.add('/Hippy_Zone/img/logo2.png');

}